//
//  MainViewController.m
//  DawnHealth
//
//  Created by Mac on 2019/11/26.
//  Copyright © 2019 hheTeamiOS. All rights reserved.
//

#import "MainViewController.h"
#import "CYLTabBarController.h"
#import "BaseNavigateionViewController.h"


@interface MainViewController ()

@end

@implementation MainViewController

+ (instancetype)create
{
    UIEdgeInsets imageInsets = UIEdgeInsetsZero;//UIEdgeInsetsMake(4.5, 0, -4.5, 0);
    UIOffset titlePositionAdjustment = UIOffsetMake(0, 0);
    MainViewController *tbc = [MainViewController tabBarControllerWithViewControllers:self.viewControllers
                                                                tabBarItemsAttributes:self.tabBarItemsAttributesForController
                                                                          imageInsets:imageInsets
                                                              titlePositionAdjustment:titlePositionAdjustment
                                                                              context:nil];
    [self customizeTabBarAppearance];
    return tbc;
    
}

+ (NSArray *)viewControllers {
    
    UIViewController *dataViewController = [DataSummaryNaviCtrl create];
    UIViewController *deviceViewController = [DeviceConnectedViewController viewController];
    UIViewController *mineViewController = [NSClassFromString(@"MineViewController") new];
    return @[
        dataViewController,
        [[BaseNavigateionViewController alloc] initWithRootViewController:deviceViewController],
        [[BaseNavigateionViewController alloc] initWithRootViewController:mineViewController]
    ];
}

+ (NSArray *)tabBarItemsAttributesForController {
    NSDictionary *dataTabBarItemsAttributes = @{
        CYLTabBarItemTitle : @"数据",
        CYLTabBarItemImage : @"tabbar_icon_home_default",
        CYLTabBarItemSelectedImage : @"tabbar_icon_home_pressed",
    };
    NSDictionary *deviceTabBarItemsAttributes = @{
        CYLTabBarItemTitle : @"设备",
        CYLTabBarItemImage : @"tabbar_icon_device_default",
        CYLTabBarItemSelectedImage : @"tabbar_icon_device_pressed",
    };
    NSDictionary *mineTabBarItemsAttributes = @{
        CYLTabBarItemTitle : @"我的",
        CYLTabBarItemImage : @"tabbar_icon_personal_default",
        CYLTabBarItemSelectedImage : @"tabbar_icon_personal_pressed",
    };
    
    NSArray *tabBarItemsAttributes = @[
        dataTabBarItemsAttributes,
        deviceTabBarItemsAttributes,
        mineTabBarItemsAttributes
    ];
    return tabBarItemsAttributes;
}


+ (void)customizeTabBarAppearance {
    
    // 普通状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = HEXCOLOR(@"FF6F00");
    
    // set the text color for selected state
    // 选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = HEXCOLOR(@"FF6F00");
    
    // set the text Attributes
    // 设置文字属性
    UITabBarItem *tabBar = [UITabBarItem appearance];
    [tabBar setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [tabBar setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    [UITabBar appearance].barTintColor = [UIColor cyl_systemBackgroundColor];
    [[UITabBar appearance] setBackgroundColor:[UIColor cyl_systemBackgroundColor]];
    
}

@end
